package lee.study.String;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class TestDemo1028 {


    public static boolean func(String string) {//判断字符串是否由数字组成
        for (int i = 0; i < string.length(); i++) {
            char j = string.charAt(i);
            if (j < '0' || j > '9') {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        String str="adbcdEfG";
        String ret=str.toUpperCase();//转大写
        String ret2=str.toLowerCase();//转小写
        System.out.println(ret);
        System.out.println(ret2);
    }

    public static void main7(String[] args) {
       String str="name=zhangsan&age=18";
        String[] str1=str.split("&");
        //str1[0]=[name=zhangsan]  str1[1]=[age=18]
        for (String s1:str1) {
            String[] str2=s1.split("=");
            //str2[0]=[name] str2[1]=[zhangsan] str2[2]=[age]  str[3]=[18]
            for (String s2:str2) {
                System.out.println(s2);
            }
        }

        /* String str="192.168.1.1";
        String[] ret=str.split("\\.");//以.*$|(){^?+这些符号分割需要在前面加\\
        System.out.println(Arrays.toString(ret));*/
    }

    public static void main6(String[] args) {
        String str="ababcabcdabcde";
        boolean flg=str.contains("abcde");
        boolean flg1=str.startsWith("abc");//判断str字符串是否以“ abc”开头的
        boolean flg2=str.startsWith("abc",2);//便宜toffset位后，判断str字符串是否以"abc"开头的
        boolean flg3=str.endsWith("cde");//判断字符串是否以"cde"结尾的
        int index=str.indexOf("abc");//返回的是找到第一次出现的字符串的下标
        int index1=str.indexOf("abc",2);//从2号下标开始找
        int index2=str.lastIndexOf("abc");//从后往前找返回第一次出现的下标
        int index3=str.lastIndexOf("abc",3);
        System.out.println(flg);
        System.out.println(index2);
    }


    public static void main5(String[] args) {
        String str1="abcdef";
        String ret=str1.substring(1);//只给一个位置，代表从这个位置开始截取到结束位置。
        String ret1=str1.substring(1,3);//截取范围在[1,3),左闭右开
        System.out.println(ret);
        System.out.println(ret1);
    }


    public static void main4(String[] args) {
        String str1="ababcabcd";
        String ret=str1.replace("ab","AB");
        String ret4=str1.replace('a','b');//replace可以替换字符也可以替换字符串
        String ret2=str1.replaceAll("ab","qw");
        String ret3=str1.replaceFirst("ab","AB");//替换第一次出现的字符串ab
        System.out.println(ret);
        System.out.println(ret2);
        System.out.println(ret3);
    }

    public static void main3(String[] args) {
        String str1 = "ABCDef";
        String str2 = "abcdef";
        System.out.println(str1.equals(str2));
        System.out.println(str1.equalsIgnoreCase(str2));//比较时忽略大小写
        System.out.println(str1.compareTo(str2));//比较字符串大小
        //str1>str2     正数
        //str1<str2     负数
        //str1=str2     0
    }


    public static void main2(String[] args) throws UnsupportedEncodingException {
       /* String str = "123456";
        System.out.println(func(str));*/
        byte[] bytes = {97, 98, 99, 100};
        String str1 = new String(bytes);
        System.out.println(str1);
        String str2 = new String(bytes, 1, 3);
        System.out.println(str2);
        String str3 = "abcdef";
        byte[] bytes1 = str3.getBytes();
        //byte[] bytes2=str3.getBytes("utf8");//这里只能填编码格式，例如gbk，utf8，并且需要声明异常
        System.out.println(Arrays.toString(bytes1));
        //System.out.println(Arrays.toString(bytes2));
    }

    public static void main1(String[] args) {
        char[] val = {'a', 'v', 'c', 's', 'd'};
        String str = new String(val);
        String str1 = new String(val, 0, 4);
        System.out.println(str);
        System.out.println(str1);
        String str2 = "hello";
        char ch = str2.charAt(1);
        System.out.println(ch);
        char[] val2 = str2.toCharArray();
        System.out.println(Arrays.toString(val2));
    }
}
